//
//  UIBarButtonItem+Extension.swift
//  新浪 weibo
//
//  Created by xuwei on 16/1/19.
//  Copyright © 2016年 xuwei. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    convenience init(imgNamed: String? = nil,title: String? = nil,target: AnyObject?,action: Selector) {
        self.init()
        
        let button = UIButton()
        
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        if let name = imgNamed{
            button.setImage(UIImage(named: name), forState: UIControlState.Normal)
            
            button.setImage(UIImage(named: "\(name)_highlighted"), forState: UIControlState.Highlighted)
        }
        if let _ = title{
            button.titleLabel?.font = UIFont.systemFontOfSize(14)
            button.setTitle(title, forState: UIControlState.Normal)
            
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
            button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
        }
        
        button.sizeToFit()
        
        customView = button
        
        
        
    }
    
    
    
}

